home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12290 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: DMI.USherb.CA!news!rollet
  2. From: rollet@oriole.DMI.USherb.CA (Romaric Rollet)
  3. Newsgroups: comp.lang.c++
  4. Subject: 'delete' dos not work !!!! (for me...)
  5. Date: 19 Mar 1996 02:55:49 GMT
  6. Organization: Universite de Sherbrooke
  7. Distribution: world
  8. Message-ID: <ROLLET.96Mar18215549@oriole.DMI.USherb.CA>
  9. NNTP-Posting-Host: oriole.dmi.usherb.ca
  10.  
  11. In that piece of code...
  12. delete never free the variable donnee (or don in the second function)...
  13.  
  14. Image*
  15. sobel(Image* im)
  16. {
  17.   Image* res;
  18.   int* donnee= new int[im->w*im->h];
  19.   int index;
  20.   int max = -65535, min = 65535;
  21.  
  22.   for(int i = 0; i < im->w - 1; i++)
  23.     for (int j = 0; j < im->h - 1; j++) {
  24.       index = i + j * im->w;
  25.       donnee[index] = -im->data[index]
  26.                         + im->data[index+1]
  27.                         - im->data[index+im->w]
  28.                         + im->data[index+1+im->w];
  29.       if (donnee[index] > max) max = donnee[index];
  30.       if (donnee[index] < min) min = donnee[index];
  31.     }
  32.  
  33.   return norm(donnee, im->w, im->h, max , min);
  34.  
  35. }
  36.  
  37. Image*
  38. norm(int* don, int w, int h, int M, int m)
  39. {
  40.   Image* res=new Image(w, h);
  41.  
  42.   for(int i = 0; i < w * h; i++)
  43.     res->data[i] = (((don[i] - m) * 255) / (M - m));
  44.  
  45.   delete don;
  46.  
  47.   return res;
  48. }
  49.  
  50. Why ?? (this is about 800Ko allocated for me and what a shame not to free it !!)
  51.  
  52. Thanxs for your answers..
  53. Romaric Rollet.
  54.  
  55.  
  56.